﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MinhTam.DataAccess.Web;

public partial class vanphong : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            loadData();
        }
        
    }
    private void loadData()
    {
        string sql = @"SELECT lvp.LOAI_VP_ID,upper(lvp.TEN_LOAI_VP) TEN_LOAI_VP
FROM LOAI_VAN_PHONG lvp
WHERE EXISTS (SELECT TOP 1 vp.VAN_PHONG_ID
                FROM VAN_PHONG vp WHERE vp.LOAI_VP_ID=lvp.LOAI_VP_ID)";
        DataTable dtLoaiVP = SQLConnectWeb.GetTable(sql);
        
        listLVP.DataSource = dtLoaiVP;
        listLVP.DataBind();

    }
    protected void listLVP_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView r = e.Item.DataItem as DataRowView;
        string sql = string.Format(@"    
                SELECT tt.TINH_THANH_ID,tt.TEN_TINH_THANH, {0} LOAI_VP_ID
                FROM TINH_THANH tt
                WHERE EXISTS(SELECT TOP 1 vp.VAN_PHONG_ID
                FROM VAN_PHONG vp WHERE vp.TINH_THANH_ID=tt.TINH_THANH_ID and vp.LOAI_VP_ID={0} ) ", r["LOAI_VP_ID"]);
        DataTable dtTT = SQLConnectWeb.GetTable(sql);
        Repeater rp = (Repeater)e.Item.FindControl("listTP");
        if (rp != null)
        {
            rp.DataSource = dtTT;
            rp.DataBind();
        }
       
    }
    protected void listTP_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        DataRowView r = e.Item.DataItem as DataRowView;
        string sql = string.Format(@"    
               SELECT vp.TEN_VAN_PHONG,vp.DIA_CHI,vp.DIEN_THOAI,vp.FAX, vp.VAN_PHONG_ID
            FROM VAN_PHONG vp
            WHERE vp.TINH_THANH_ID={0} AND vp.LOAI_VP_ID={1}
            ORDER BY vp.TEN_VAN_PHONG", r["TINH_THANH_ID"], r["LOAI_VP_ID"]);
        DataTable dtVP = SQLConnectWeb.GetTable(sql);
        Repeater rp = (Repeater)e.Item.FindControl("listVP");
        if (rp != null)
        {
            rp.DataSource = dtVP;
            rp.DataBind();
        }

    }
}